package com.wxg.config.rabbitmq;

import com.wxg.common.core.dto.Address;
import com.wxg.domain.RabbitMqConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

/**
 * @author void
 * @date 2019/12/30 9:55
 * @desc @RabbitListener修饰类时对于消费的方法需要加@RabbitHandler,可以用来支持不同参数的方法
 */
@Slf4j
@Component
@Conditional(value = RabbitCondition.class)
public class RabbitReceiver {

    @RabbitListener(queues = RabbitMqConstant.QUEUE_HELLO)
    public void consume(String message){
        System.out.println("HelloRabbitReceiver.consume "+message);
    }

    @RabbitListener(queues = RabbitMqConstant.QUEUE_MANY)
    public void consume1(String message){
        System.out.println("ManyReceiver.consume1 "+message);
    }

    @RabbitListener(queues = RabbitMqConstant.QUEUE_MANY)
    public void consume2(String message){
        System.out.println("ManyReceiver.consume2 "+message);
    }

    @RabbitListener(queues = RabbitMqConstant.QUEUE_TOPIC_MESSAGE)
    public void processMessage1(String message){
        log.info("message消费,消息内容:{}",message);
    }

    @RabbitListener(queues = RabbitMqConstant.QUEUE_TOPIC_MESSAGES)
    public void processMessage2(String message){
        log.info("messages消费,消息内容:{}",message);
    }

    @RabbitListener(queues = RabbitMqConstant.QUEUE_OBJECT)
    public void consume(Address address){
        //传对象,需要对象实现序列化接口,要么修改Rabbit的序列化配置
        System.out.println("ObjRabbitReceiver.consume "+ address.toString());
    }

    @RabbitListener(queues = RabbitMqConstant.QUEUE_FANOUT_A)
    public void processMessageA(String message){
        log.info("广播消费A  消息内容:{}", message);
    }

    @RabbitListener(queues = RabbitMqConstant.QUEUE_FANOUT_B)
    public void processMessageB(String message){
        log.info("广播消费B  消息内容:{}", message);
    }

    @RabbitListener(queues = RabbitMqConstant.QUEUE_FANOUT_C)
    public void processMessageC(String message){
        log.info("广播消费C  消息内容:{}", message);
    }
}
